package com.itshare.video.util;

import com.itshare.video.pojo.code.MessageType;
import com.itshare.video.pojo.dto.UserTokenDTO;
import com.itshare.video.pojo.po.UserMessage;

import java.util.Date;
import java.util.Optional;

/**
 * @Author lyr
 * @create 2020/10/31 15:46
 */
public class MessageUtil {
    public static UserMessage getSysMsg(UserTokenDTO userTokenDTO) {
        UserMessage userMessage = new UserMessage();
        userMessage.withMessageType(MessageType.SYS_MSG.type)
                .withToUserMessage("您的视频已经发布，等待管理员通过")
                .withMessageType(MessageType.SYS_MSG.type)   /*系统消息 */
                .withCreateTime(new Date())
                .withHasRead(0)
                .withUpdateTime(new Date())
                .withFromUserName("sys")
                .withToUserId(userTokenDTO.getId()); //消息推送
        return userMessage;
    }

    public static UserMessage videoPermitMsg(Integer permitStatus, Integer toUserId, String content) {
        UserMessage userMessage = new UserMessage();
        if (permitStatus == 1) {
            userMessage
                    .withMessageType(MessageType.VIDEO_PASS.type)
                    .withToUserMessage("您的视频审核通过")
                    .withCreateTime(new Date())
                    .withHasRead(0)
                    .withToUserId(toUserId)
                    .withUpdateTime(new Date())
                    .withFromUserName("sys");
        } else {
            userMessage
                    .withMessageType(MessageType.VIDEO_NO_PASS.type)
                    .withToUserMessage("您的视频审核没有通过 " + Optional.ofNullable(content).orElse(""))
                    .withCreateTime(new Date()).withUpdateTime(new Date())
                    .withToUserId(toUserId)

                    .withHasRead(0)
                    .withFromUserName("sys");
        }
        return userMessage;
    }

    public static UserMessage getDefaultMsg() {
        UserMessage userMessage =new UserMessage()
                .withUpdateTime(new Date())
                .withCreateTime(new Date())
                .withDeleteStatus(0)
                .withHasRead(0);
        return userMessage;
    }

    /**
     * 视频删除提醒
     * @param toUserId
     * @return
     */
    public static UserMessage setVideoDelete(Integer toUserId) {
        return getDefaultMsg()
                .withMessageType(MessageType.SYS_MSG.type)
                .withToUserId(toUserId);
    }
}
